package org.datasays.wes.benchmark.impl.jest;

import io.searchbox.action.AbstractMultiTypeActionBuilder;
import io.searchbox.action.GenericResultAbstractAction;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class DeleteByQuery extends GenericResultAbstractAction {

	protected DeleteByQuery(Builder builder) {
		super(builder);

		this.payload = "{\"query\":" + builder.query + "}";
		setURI(buildURI());
	}

	@Override
	protected String buildURI() {
		return super.buildURI() + "/_delete_by_query";
	}

	@Override
	public String getPathToResult() {
		return "ok";
	}

	@Override
	public String getRestMethodName() {
		return "POST";
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.appendSuper(super.hashCode())
				.toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		return new EqualsBuilder()
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	public static class Builder extends AbstractMultiTypeActionBuilder<DeleteByQuery, Builder> {

		private String query;

		public Builder(String query) {
			this.query = query;
		}

		@Override
		public DeleteByQuery build() {
			return new DeleteByQuery(this);
		}
	}

}
